package com.wuhao.lib_base.utils;

import android.content.Context;
import android.widget.Toast;

import androidx.annotation.NonNull;

import es.dmoral.toasty.Toasty;


/**
 * Created by Mr.Hao on 2017/3/27 00:58.
 */

public class ToastyUitl {
    static int time;
    static Toast toast;

    /**
     * 原生实现，显示吐司
     * @param context
     * @param message
     * @param isLong
     */
    public static void showToast(@NonNull Context context, @NonNull CharSequence message, @NonNull boolean isLong) {
        if (isLong) {
            time = Toast.LENGTH_LONG;
        } else {
            time = Toast.LENGTH_SHORT;
        }
        if (toast == null) {
            toast = Toast.makeText(context, message, time);
        } else {
            toast.setText(message);
        }
        toast.show();
    }

    public static void showTimeToast(@NonNull Context context, @NonNull CharSequence message, @NonNull int duration) {
        if (toast == null) {
            toast = Toast.makeText(context, message, duration);
        } else {
            toast.setText(message);
        }
        toast.show();
    }

    public static void hideToast(@NonNull Context context, @NonNull CharSequence message, @NonNull int duration) {
        if (toast != null) {
            toast.cancel();
        }
    }

    public static void successToasty(@NonNull Context context, @NonNull CharSequence content) {
        Toasty.success(context, content).show();
    }

    public static void errorToasty(@NonNull Context context, @NonNull CharSequence content) {
        Toasty.error(context, content).show();
    }

    public static void infoToasty(@NonNull Context context, @NonNull CharSequence content) {
        Toasty.info(context, content).show();
    }

    public static void warnToasty(@NonNull Context context, @NonNull CharSequence content) {
        Toasty.warning(context, content).show();
    }

}
